package view;

import command.*;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.*;

import network.LocalNetworkSettings;

@SuppressWarnings("serial")
public class ChatGUI extends JFrame implements WindowListener {
	
	protected LogScreen logscreen;
	protected DebugScreen debugscreen;
	protected ChatScreen chatscreen;
	
	
	protected JPanel content;
	protected CardLayout cl;
	protected String[] listContent = {"HOME", "DEBUG", "CHAT"};
	
	public ChatGUI()
	{
		initComponents();
	}
	
	public JPanel getContentPanel()
	{
		return content;
	}
	
	public CardLayout getCardLayout()
	{
		return cl;
	}
	
	public DebugScreen getDebugScreen()
	{
		return debugscreen;
	}
	
	public ChatScreen getChatScreen()
	{
		return chatscreen;
	}
	
	private void initComponents()
	{
		this.setSize(400, 500);
		this.setTitle("Fenetre de connexion du chat");
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		content = new JPanel();
		cl = new CardLayout();
		
		debugscreen = new DebugScreen();
		logscreen = new LogScreen(debugscreen);
		chatscreen = new ChatScreen();
		
	    content.setLayout( cl );
		
		content.add(logscreen, listContent[0]);
	    content.add(debugscreen, listContent[1]);
	    content.add(chatscreen, listContent[2]);
	    this.getContentPane().add(content, BorderLayout.CENTER);
	    
	    
	    if(LocalNetworkSettings.displayDebug)
	    {
	    	JPanel boutonPanel = new JPanel();
	    	ChatButton bouton = new ChatButton("Debug screen", new NextPanel());
	    	boutonPanel.add(bouton);
	    	this.getContentPane().add(boutonPanel, BorderLayout.NORTH);
	    }
		
		this.pack();
	    this.setVisible(true);
	}
	
	// Invoked when the Window is set to be the active Window.
	public void windowActivated(WindowEvent e)
	{
			
	}
	    
	// Invoked when a window has been closed as the result of calling dispose on the window.
	public void windowClosed(WindowEvent e)
	{
		// send BYE before leaving
		(new LogOut()).execute();
	}
		
	// Invoked when the user attempts to close the window from the window's system menu.
	public void windowClosing(WindowEvent e)
	{
		
	}
	    
	// Invoked when a Window is no longer the active Window.
	public void windowDeactivated(WindowEvent e)
	{
		
	}
	    
	// Invoked when a window is changed from a minimized to a normal state.
	public void windowDeiconified(WindowEvent e)
	{
		
	}
	    
	// Invoked when a window is changed from a normal to a minimized state.
	public void windowIconified(WindowEvent e)
	{
		
	}
	    
	// Invoked the first time a window is made visible.
	public void windowOpened(WindowEvent e)
	{
		
	}
}
